import re
from pathlib import Path
import argparse

DIGIT_RE = re.compile(r"[\d\uFF10-\uFF19]+")  # 包含 ASCII 数字与全角数字


def remove_digits_from_text(text: str) -> str:
    """
    从文本中移除所有数字（包括全角数字），返回处理后的文本。
    """
    return DIGIT_RE.sub("", text)


def process_file(
    src_path: str, dst_path: str = None, inplace: bool = False, encoding: str = "utf-8"
):
    src = Path(src_path)
    if not src.exists():
        raise FileNotFoundError(f"文件不存在: {src_path}")
    text = src.read_text(encoding=encoding)
    cleaned = remove_digits_from_text(text)
    if inplace:
        dst = src
    else:
        dst = (
            Path(dst_path)
            if dst_path
            else src.with_name(src.stem + "_cleaned" + src.suffix)
        )
    dst.write_text(cleaned, encoding=encoding)
    return str(dst)


if __name__ == "__main__":

    out = process_file("./过秦论.txt", inplace=True)
    print("out", out)
